Skip to content

perf: optimize round in datafusion-functions#23471

Open
andygrove wants to merge 1 commit into
apache:mainfrom
andygrove:auto-opt/round-datafusion-20260710-185523
Open

perf: optimize round in datafusion-functions#23471
andygrove wants to merge 1 commit into
apache:mainfrom
andygrove:auto-opt/round-datafusion-20260710-185523

Conversation

@andygrove

@andygrove andygrove commented Jul 11, 2026

Copy link
Copy Markdown
Member

Which issue does this PR close?

N/A

Rationale for this change

Optimize an existing function

What changes are included in this PR?

round() over a no-null float column with scalar decimal_places now hoists the 10^dp factor out of the loop and uses the vectorizable infallible unary kernel instead of per-element try_unary+powi, with a fallback preserving bit-identical output for null/array cases.

Are these changes tested?

Existing tests

Benchmark (criterion):

  • 8192: 28.689% faster (base 2711ns -> cand 1933ns)
  • 4096: 41.544% faster (base 1382ns -> cand 808ns)
  • 1024: 25.253% faster (base 451ns -> cand 337ns)
  • 8192: 44.103% faster (base 1486ns -> cand 831ns)
  • 4096: 29.01% faster (base 679ns -> cand 482ns)
  • 1024: 20.457% faster (base 291ns -> cand 231ns)

Are there any user-facing changes?

No

@github-actions github-actions Bot added the functions Changes to functions implementation label Jul 11, 2026
@andygrove andygrove marked this pull request as ready for review July 11, 2026 01:51
Comment on lines +877 to +880
/// compiler can autovectorize. Requiring no null slots keeps the output
/// bit-identical to the fallible kernel: `unary` writes a computed value into
/// every slot while `try_unary` leaves null slots zeroed, so the two only agree
/// when there are no null slots. Returns `Ok(None)` when the fast path does not

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i feel we dont need to aim for this bit-identical approach? we can still apply this fast path even if there are nulls since the nulls should be masked anyway

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants